package com.back.common;
//拦截器
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

@Configuration//配置类
public class InterceptorConfig extends WebMvcConfigurationSupport {

    @Override//addInterceptors是WebMvcConfigurationSupport中自带的空函数，必须自定义
    protected void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(jwtInterceptor())//配置jwt的拦截器规则
                .addPathPatterns("/**")//   "/**"->拦截所有的请求路径
                .excludePathPatterns("/","/Resgiter","/userLogin","/Login");
        super.addInterceptors(registry);
    }

    @Bean//注入到spring中
    public JwtInterceptor jwtInterceptor() {
        return new JwtInterceptor();
    }

}
